﻿@using System.IO;
@using System.Linq;
@using FruitCake.SimpleGallery.Models;

@{
    Style.Include("simpleGallery.css").AtHead();

    IEnumerable<SimpleGalleryImage> images = (IEnumerable<SimpleGalleryImage>)Model.Images;
    IEnumerable<SimpleGalleryImage> prevImages = null;
    IEnumerable<SimpleGalleryImage> nextImages = null;

    if (Model.PrevImages != null) { prevImages = (IEnumerable<SimpleGalleryImage>) Model.PrevImages; }
    if (Model.NextImages != null) { nextImages = (IEnumerable<SimpleGalleryImage>)Model.NextImages; }
    
    var count = images.Count();

    var part = (SimpleGalleryPart) Model.ContentPart;

    string frameSizeStyle = "", imgSizeStyle = "", liWidthStyle = "";
    if (part.HasFrameSize)
    {
        liWidthStyle = String.Format("width: {0}px;", part.FrameWidth);
        frameSizeStyle = String.Format("width: {0}px; height: {1}px", part.FrameWidth, part.FrameHeight);
        imgSizeStyle = String.Format("max-width: {0}px; max-height: {1}px", part.FrameWidth, part.FrameHeight);        
    }
}

@if (part.LinkMode == LinkMode.LightBox)
{
    Style.Include("jquery.lightbox-0.5.css");
    Script.Require("jQuery");
    Script.Include("jquery.lightbox-0.5.min.js");

    using (Script.Foot())
    {        
    <script type="text/javascript">
        $(function () {
            $('.simpleGalleryContainer a').lightBox({
                imageLoading: '@Url.Content("~/Modules/FruitCake.SimpleGallery/Content/Images/lightbox-ico-loading.gif")',
                imageBtnClose: '@Url.Content("~/Modules/FruitCake.SimpleGallery/Content/Images/lightbox-btn-close.gif")',
                imageBtnPrev: '@Url.Content("~/Modules/FruitCake.SimpleGallery/Content/Images/lightbox-btn-prev.gif")',
                imageBtnNext: '@Url.Content("~/Modules/FruitCake.SimpleGallery/Content/Images/lightbox-btn-next.gif")',
                imageBlank: '@Url.Content("~/Modules/FruitCake.SimpleGallery/Content/Images/lightbox-blank.gif")',
                txtImage: '@T("Image")',
                txtOf: '@T("of")'
            });
        });
    </script>
    }
}

<div class="simpleGalleryClearGroup"></div>
<div class="simpleGalleryContainer">
    @if (images != null && count > 0)
    {

        if (prevImages != null)
        {
            foreach (var img in prevImages)
            {
                @:<a href="@img.FilePath" target="_blank" style="display: none"></a>
            }
        }
        
        <ul class="simpleGallery">
            @foreach (var img in images)
            { 
                <li style="@liWidthStyle">
                    @if(part.TitleMode == TitleMode.Above)                    
                    {
                        @: <span class="simpleGalleryImageTitle">@img.Title</span>
                    }
                    <div class="simpleGalleryFrame" style="@frameSizeStyle">
                        @if (part.LinkMode != LinkMode.None)
                        {
                            @:<a href="@img.FilePath" target="_blank">
                        }
                        <img src="@img.ThumbnailResolvedPath" class="simpleGalleryThumbnail" alt="@img.Name" title="@img.Title" style="@imgSizeStyle" />                    
                        @if (part.LinkMode != LinkMode.None)
                        {
                            @:</a>
                        }
                    </div>
                    @if(part.TitleMode == TitleMode.Below)     
                    {              
                        @: <span class="simpleGalleryImageTitle">@img.Title</span>
                    }
                </li>
            }
        </ul>
    
        if (nextImages != null)
        {
            foreach (var img in nextImages)
            {
                @:<a href="@img.FilePath" target="_blank" style="display: none"></a>
            }
        }
    }
</div>
<div class="simpleGalleryClearGroup"></div>

@using (Html.BeginFormAntiForgeryPost()) { 
	@Display(Model.TestPager)
} 